package itsm.isperp.module.service.problem.rule;

import itsm.isperp.module.entity.problem.ProbAutoTriggerRule;
import itsm.isperp.module.service.problem.ProbAutoTriggerRulePaser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * 同一类型资产并且同一类型事件
 * 
 * @author lizx
 * @date 2015-7-26
 * @since 1.0
 * 
 */
public class ProbAutoTriggerRulePaserUtils {

	public static void paser(Map<String, Counter> mapper,
			Map<String, Counter> rmapper, ProbAutoTriggerRule rule, String key,
			String idValue) {

		if (rmapper.containsKey(key)) {

			Counter cou = rmapper.get(key);
			cou.setCount(cou.getCount() + 1);
			cou.addToList(idValue);

		} else if (mapper.containsKey(key)) {

			Counter cou = mapper.get(key);
			cou.setCount(cou.getCount() + 1);
			cou.addToList(idValue);
			if (cou.getCount() >= rule.getOccurTimes()) {
				mapper.remove(key);
				rmapper.put(key, cou);
			}

		} else {

			Counter cou = new Counter();
			cou.addToList(idValue);
			mapper.put(key, cou);
			if (cou.getCount() >= rule.getOccurTimes()) {
				mapper.remove(key);
				rmapper.put(key, cou);
			}
		}

	}
}
